package packVistas;

import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import packLigaDeFutbol.GestorEquipos;
import packLigaDeFutbol.Principal;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class MenuEquipos extends JDialog {

	private static final long serialVersionUID = -7982408931495091255L;
	private final JPanel contentPanel = new JPanel();
	private static int idEquipo;
	
	public MenuEquipos() {

		inicializarVentana();
		
		botonGestionarJugadores();
		botonFichajes();
		botonConsultarCalendario();
		botonConsultarDatos();
		botonCerrar();
		
		idEquipo = GestorEquipos.getGestorEquipos().obtenerEquipoPorIDUsu(Principal.idUsu);
		
	}
	
	public void inicializarVentana(){
		setResizable(false);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setModal(true);
		setTitle("Men\u00FA Equipo");
		setBounds(100, 100, 236, 204);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new FormLayout(new ColumnSpec[] {
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));
	}
	
	
	public void botonGestionarJugadores(){
		JButton btnGestion = new JButton("Gestionar Jugadores");
		contentPanel.add(btnGestion, "1, 1");
		
		btnGestion.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			GestionarJugadores gj = new GestionarJugadores(idEquipo);
			gj.setVisible(true);
		}
	});
	}
	
	public void botonFichajes(){
		JButton btnFichajes = new JButton("Fichajes");
		btnFichajes.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Fichajes f = new Fichajes();
				f.setVisible(true);
			}
		});
		contentPanel.add(btnFichajes, "1, 3");
	}
	
	public void botonConsultarCalendario(){
		JButton btnConsultarCalendario = new JButton("Consultar Calendario");
		btnConsultarCalendario.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ConsultarCalendario cc = new ConsultarCalendario();
				cc.setVisible(true);
			}
		});
		contentPanel.add(btnConsultarCalendario, "1, 5");
	}
	
	public void botonConsultarDatos(){
		JButton btnConsultarDatos = new JButton("Consultar datos de la Liga");
		btnConsultarDatos.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			ConsultarDatos cd = new ConsultarDatos();
			cd.setVisible(true);
			}
		});
		btnConsultarDatos.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				new SeleccionTemporada(new ConsultarPartido());
				
			}
		});
		contentPanel.add(btnConsultarDatos, "1, 7");
	}
	
	public void botonCerrar(){
		JButton btnCerrar = new JButton("Cerrar");
		btnCerrar.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				dispose();
			}
		});
		contentPanel.add(btnCerrar, "1, 11");
	}

	public static int getIdEquipo(){
		return idEquipo;
		
	}
	
}

